import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { getDeviceTypeAlias } from "./deviceType.api"
import { h } from 'vue';
import { Icon } from '/@/components/Icon';
import { render } from '/@/utils/common/renderUtils';
import { isNullOrUnDef, isEmpty } from '/@/utils/is';

export const columns: BasicColumn[] = [
  {
    title: '类型名称',
    dataIndex: 'name',
    width: 200,
    align: 'left',
  },
  {
    title: '类型别名',
    dataIndex: 'alias',
    customRender: ({ text }) => {
      return render.renderDict(text, 'iot_device_type_alias');
    },
    width: 200,
  },
  {
    title: '类型说明',
    dataIndex: 'remark',
    width: 200,
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '类型名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'alias',
    label: '类型别名',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    label: 'id',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    field: 'name',
    label: '类型名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'pid',
    label: '父类型',
    component: 'TreeSelect',
    required: true,
    defaultValue: '0',
    componentProps: {
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
      dropdownStyle: {
        maxHeight: '50vh',
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'alias',
    label: '类型别名',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'iot_device_type_alias',
      placeholder: '请选择类型别名',
      stringToNumber: false,
      getPopupContainer: () => document.body,
    },
  },
  // {
  //   field: 'alias',
  //   label: '类型别名',
  //   component: 'ApiTreeSelect',
  //   componentProps: {
  //     api: getDeviceTypeAlias,
  //     resultField: 'list',
  //     getPopupContainer: () => document.body,
  //   },
  // },
  {
    field: 'remark',
    label: '类型说明',
    component: 'Input',
  },
];